package main

import (
	"fmt"
	"strings"
)

// 流水线部件， 把string拆成单词然后往下一个流水线传递
func main() {
	v := make(chan string, 1)
	go sourceGo("hello world", v)
	printlnGo(v)
}

func sourceGo(str string, c chan<- string) {
	strItems := strings.Fields(str)
	defer close(c)

	for _, v := range strItems {
		c <- v
	}
}

func printlnGo(result <-chan string) {
	for {
		v, ok := <-result
		if !ok {
			fmt.Println("result 已经关闭")
			return
		}

		fmt.Println(v)
	}
}
